import os
from shutil import *



def spliteFile():
    src="F:\Camera_20200430\\"
    dst="F:\Camera_20200430"
    foldSize=4*1024*1024*1024-200*1024*1024
    
    flst=os.listdir(src)

    print(os.path.getsize(src))
    n=1

    for name in flst:

        print(dst+str(n))
        newpath=dst+str(n)+"\\"

        print('newpath:'+newpath+"   n="+str(n)+"   name:"+name+"   foldSize:"+str(foldSize))
        if not os.path.exists(newpath):
          os.makedirs(newpath)
        print("getFoldSize(newpath)="+str(int(getFoldSize(newpath))))   

        if getFoldSize(newpath)+os.path.getsize(src+name)>foldSize:
           
            n=n+1
            newpath=dst+str(n)+"\\"
            os.makedirs(newpath)
        copy2(src+name,newpath+name)
            



def getFoldSize(path):

    flst=os.listdir(path)

    sumSize=0
    #print("getFoldSize:"+path)
    for name in flst:
        #print(name+'  '+str(os.path.getsize(path+name)/1000/1000))
        sumSize+=os.path.getsize(path+name)
        
    return sumSize

spliteFile()
#print(str(getFoldSize("F:\Camera_20200430\\")))
print('exe finished!')
